<%@page contentType="text/html; charset=UTF-8" %>
<jsp:useBean id="user" class="entity_beans.User" scope="session"></jsp:useBean>
<jsp:useBean id="auxBean" class="model.AuxBean" scope="request"></jsp:useBean>

<%@page import="entity_beans.Flight" %>
<%@page import="entity_beans.Passenger" %>
<%@page import="utils.DateTest"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Air Transport - Passengers on Flight</title>
</head>
<body>
<%!Flight flight = null;%>
<%
	if (user.isAccessed() == false) {
		response.sendRedirect("../index.jsp");
		return;
	}

	if ( user.isLoggedIn() == false ) {
		response.sendRedirect("../index.jsp");
		return;
	}
	
	String flightID = request.getParameter("flightid");
	
	flight = auxBean.getFlightByID(flightID);
	
	if (flight == null) {
		response.sendRedirect("main.jsp");
		return;
	}
%>



<h2><u>Air Transport Service - Passengers on Flight</u></h2>

<jsp:include page="header.jsp"></jsp:include>


	<table border="1">
		<tr bgcolor="lightgrey">
			<td style="BACKGROUND-COLOR: #b7d0ec;">Flight ID:</td><td style="BACKGROUND-COLOR: #e7cfad;"><%=flight.getId()%></td>
		</tr>
		<tr bgcolor="lightgrey">
			<td style="BACKGROUND-COLOR: #b7d0ec;">Departure Time:</td><td style="BACKGROUND-COLOR: #e7cfad;"><%=flight.getDepartureTimeFormated()%></td>
		</tr>
		<tr bgcolor="lightgrey">
			<td style="BACKGROUND-COLOR: #b7d0ec;">Source:</td><td style="BACKGROUND-COLOR: #e7cfad;"><%=flight.getSource()%></td>
		</tr>
		<tr bgcolor="lightgrey">
			<td style="BACKGROUND-COLOR: #b7d0ec;">Destination:</td><td style="BACKGROUND-COLOR: #e7cfad;"><%=flight.getDestination()%></td>
		</tr>
	</table>
	
<hr />

	<table border="1">
		<tr bgcolor="lightgrey">
			<th>Passenger</th>
			<th>Reservation</th>
		</tr>
<%
	for (Passenger pass : auxBean.getPassengersByFlight(flightID)) {
%>
	<tr>
		<td><a href='passenger.jsp?jmbg=<%=pass.getJmbg()%>'><%=pass.toString()%></a></td>
<%
	if (DateTest.testDate(flight.getDepartureTime()) == false) {
%>
		<form method="get" action="cancellation.jsp">
			<td align="center">	
				<input type="hidden" name="jmbg" value=<%= pass.getJmbg() %>>
				<input type="hidden" name="flightid" value=<%= flight.getId() %>>
				<input type="submit" value="Cancel">
			</td>
		</form>
	
<%
	} else {
%>
	<td>Cancel Exp.</td>
<%
	}
%>
	</tr>
<%	
}
%>
	</table>	


<hr />
<p>
<a href="main.jsp">Main Page - Flight List</a>
</p>
<p>
<a href="../LogoutServlet">Logout</a>
</p>

<jsp:include page="footer.jsp"></jsp:include>
		
</body></html>